package com.ziqikeji.socket.clientThread;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * 客户端接收数据的线程类
 * @author bcs
 */
public class Cread extends Thread{
    private Socket r;
    public Cread(Socket r) {
        this.r = r;
    }
    @Override
    public void run() {
        try {
            while (true) {
                //获取输入流
                InputStreamReader is = new InputStreamReader(r.getInputStream());
                BufferedReader br = new BufferedReader(is);
                //按行读取从服务器发来的数据消息
                String content = br.readLine();
                System.out.println(content);
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
